<!DOCTYPE html>

<html lang='en'>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./lib/react.development16.4.0.js"></script>
    <script src="./lib/react-dom.development16.4.0.js"></script>
    <script src="./lib/babel.min.js"></script>
    <style>
       .s1{
           color: aqua;
           border: 1px slateblue solid;
       }
       .s2{
           color: hotpink;
           border: 1px sandybrown solid;
       }
    </style>
</head>

<body>
    <div id="app">
    </div>
    <script type="text/babel">
         function Login(props) {
            if(props.ishow){
             return <h1 className="s1">这里是登录信息页面</h1>
            }
            return <h1></h1>
         }

         function Register(props) {
             if(props.ishow){
              return <h1 className="s2">这里是注册信息页面</h1>
             }
             return <h1></h1>
         }

         
       class Welcome extends React.Component {
            constructor(props) {
                super(props)
                this.headlerClick = this.headlerClick.bind(this);//绑定headlerClick函数到组件中，可以使用this
                this.state = {ishow: true,ishows:false}; //组件的状态属性
            }
            
            headlerClick(){
              //改变组件的状态只能使用this.setState方法来实现
              this.setState({
                ishow: !this.state.ishow,
                ishows:!this.state.ishows
                });
            }
             render() {
                 return (
                     <div>
                         <button type="button" onClick={this.headlerClick}>toggle</button>
                         <hr/>
                         <Login ishow={this.state.ishow}/>
                         <Register ishow={this.state.ishows}/>
                     </div>
                 )
             }
         }
         

        const el = <Welcome/>
        ReactDOM.render(
            el,document.getElementById('app')
        );
    </script>
</body>

</html>